﻿Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging

Partial Public Class LoadBanner
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim advertisementId As Integer

        ' Try to get an advertisementID from the query string
        If Int32.TryParse(Request.QueryString.Item("ID"), advertisementId) Then
            LogImpression(advertisementId)
            LoadBanner(advertisementId)
        Else
            ' No response given
            Response.Clear()
        End If

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="advertisementId"></param>
    ''' <remarks></remarks>
    Private Sub LoadBanner(ByVal advertisementId As Integer)
        Dim manager As New BLL.AdvertisementManager

        Dim ad As Domain.dnc_Advertisement = manager.GetAdvertisementByID(advertisementId)

        DisplayImage(ad.ImageID)
    End Sub

    Private Sub DisplayImage(ByVal imageID As Integer)
        Dim manager As New BLL.ImageManager
        Dim img As Domain.dnc_Image = manager.GetImageByID(imageID)

        Response.Clear()

        Response.ContentType = img.ContentType

        Response.BinaryWrite(img.Image)

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="advertisementID"></param>
    ''' <remarks></remarks>
    Private Sub LogImpression(ByVal advertisementID As Integer)
        Dim manager As New BLL.ImpressionManager

        manager.InsertImpression(advertisementID)
    End Sub

End Class